private string Tel; // The first phone number private string teltwo; // The second phone number public address () {} Public Address (string Street, string city, int zip, string Tel, string teltwo) {This. street = Street; this. city = cityw.this.zip = zip; this. tel = Tel; this. teltwo = teltwo;} Public String getstreet () {return Street;} public void setstreet (string Street) {This. street = Street;} Public String getcity () {return city;} public void setcity (string city) {This. city = city;}
; // public Address () {} public Address (String street, String city, int zip, String tel, String telTwo) {this. street = street; this. city = city; this.zip = zip; this. tel = tel; this. telTwo = telTwo;} public String getStreet () {return street;} public void setStreet (String street) {this. street = street;} public String getCity () {return city;} public void setCity (String city) {this. city = city;} public int getZip () {return zip;} public void setZip (int zip) {this.zip = zip;} public Str
Convert Java basic data to Json code, and convert java data to json
JSON is a lightweight data exchange format, which is very suitable for the interaction between servers and JavaScrip
Examples on the official website
JSON-lib is a Java class package used to convert beans, maps, and XML into JSON and convert JSON back to bean and dynabean.: Http://json-lib.sourceforge
JSON directly into the specified custom object, where list is fully parsed and map is not fully parsedMybeanwithperson Diybean = (Mybeanwithperson) Jsonobject.tobean (Jsonobject.fromobject (JSON), MyBeanWithPerson.class , Classmap);System.out.println (Diybean);System.out.println ("Do the list release");listfor (person O:list) {Person P = (person) o;System.out.pr
Using Gson to convert a map to JSONGson (also known as Google Gson) is an open-source Java library published by Google, which uses either a serialized Java object as a JSON string or a drag-formatted JSON string as a
is not fully parsedMybeanwithperson Diybean = (Mybeanwithperson) Jsonobject.tobean (Jsonobject.fromobject (JSON), MyBeanWithPerson.class , Classmap);System.out.println (Diybean);System.out.println ("Do the list release");listfor (person O:list) {Person P = (person) o;System.out.println (P.getname ());}System.out.println ("Do the map release");To register the converter in the Registrar, you need to use the
);Classmap.put ("Map", Map.class);Use the hint to parse the JSON directly into the specified custom object, where list is fully parsed and map is not fully parsedMybeanwithperson Diybean = (Mybeanwithperson) Jsonobject.tobean (Jsonobject.fromobject (JSON), MyBeanWithPerson.class , Classmap);System.out.println (Diybean)
:{name: ' test1 '},testtwo:{name: ' Test2 '}}"; Map Classmap=NewHashMap (); Classmap.put ("List", person.class); Classmap.put ("Map", map.class); //use the hint to parse the JSON directly into the specified custom object, where list is fully parsed and map is not fully parsedMybeanwithperson Diybean = (Mybeanwithperson
The method page for converting a JSON string to a Map object transmits a json string to the background action. You need to convert the json string to a Map object.
Public Map
T
The recent project needs to connect with the customer a WebService interface, the customer that JSON string over, belong to the more complex JSON string, here to share with you in my project used in the Analytic method:The method requires the following jar Packagecom.test;Importjava.util.ArrayList;ImportJava.util.HashMap;ImportJava.util.Iterator;Importjava.util.List;ImportJava.util.Map;ImportNet.sf.json.JSO
Jackson configured the Jsonbinder to determine which JSON object to convert,In spring configurationOrg.springframework.http.converter.json.MappingJackson2HttpMessageConverter /*** Create a binder.*/ that outputs all properties to a JSON string publicstaticjsonbinderbuildnormalbinder () { returnnewjsonbinder (inclusion.always);} /*** Create a binder. that only out
Page to pass a JSON string to the back of the action, you need to convert the JSON string into a map object
Public map
The above method of converting the JSON string into a map
First, import the following jar packagesHere are the various types of programs that convert to JSON and extract data from JSONPackage Jsontest;import Java.util.arraylist;import java.util.hashmap;import java.util.list;import java.util.Map; Import Net.sf.json.jsonarray;import Net.sf.json.jsonobject;public class Jsonmain {public static void main (string[] args ) {GetList (setlist ()); Getmap (Setmap ()); Syste
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.